﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel.DataAnnotations.Schema;
using System.ComponentModel.DataAnnotations;
using RooHui.Infrastructure.Entities.EFContext;
using RooHui.Infrastructure.Entities.Repository;
using RooHui.Infrastructure.Entities.Enum;

namespace RooHui.Infrastructure.Entities.Entity
{
    public class Secret : IAccessible<U_Secret, Secret>, ILogicEntity<U_Secret, Secret>
    {
        public int ID { get; set; }
        public string UserName { get; set; }
        public string Key { get; set; }
        public string Value { get; set; }
        public SecretType Type { get; set; }
        public DateTime CreateTime { get; set; }

        protected override void Covariant(U_Secret model)
        {
            if (model != null)
            {
                this.CreateTime = model.CreateTime;
                this.ID = model.ID;
                this.Key = model.Key;
                this.Type = (SecretType)model.Type;
                this.UserName = model.UserName;
                this.Value = model.Value;
            }
        }

        protected override U_Secret Inverter(Secret model)
        {
            if (model != null)
            {
                return new U_Secret()
                {
                    CreateTime = model.CreateTime,
                    ID = model.ID,
                    Key = model.Key,
                    Type = (int)model.Type,
                    UserName = model.UserName,
                    Value = model.Value
                };
            }
            return null;
        }

        public Secret Set(U_Secret dbModel)
        {
            Covariant(dbModel);
            return this;
        }
    }
}
